// routes/index.js
const fs = require('fs')
const router = require('koa-router')()
/**
 * @swagger
 * definitions:
 *   user:
 *     properties:
 *       name:
 *         type: string
 *       breed:
 *         type: string
 *       age:
 *         type: integer
 *       sex:
 *         type: string
 */
router.get('/index', async (ctx, next) => {
 ctx.body = '哈哈哈哈'
})

/**
 * @swagger
 *
 * /about:
 *   get:
 *     tags:
 *       - 用户
 *     description: about to the application
 *     produces:
 *       - application/json
 *     parameters:
 *       - name: username
 *         description: Username to use for login.
 *         in: formData
 *         required: true
 *         type: string
 *       - name: password
 *         description: User's password.
 *         in: formData
 *         required: true
 *         type: string
 *     responses:
 *       200:
 *         description: login
 */
router.get('/about/:id', async (ctx, next) => {
  ctx.type = 'text/html'
  ctx.body = fs.createReadStream('./views/index.html')
})

router.get('/test/:name', async (ctx, next) => {
  console.log(name)
  await ctx.render('test', {
    title: 'Hello Koa'
  })
})

module.exports = router
